package com.project.demo.service.impi;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.demo.entity.Evaluate;
import com.project.demo.mapper.Evaluatemapper;
import com.project.demo.service.EvaluateService;
import com.project.demo.vo.AllEvaluateVo;
import com.project.demo.vo.EvaluateVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EvaluateServiceimpi implements EvaluateService {
    @Autowired
    private Evaluatemapper evaluatemapper;

    @Override
    public EvaluateVo<AllEvaluateVo> FindEvaluateVo(Integer page, Integer limit) {
        EvaluateVo evaluateVo = new EvaluateVo();
        evaluateVo.setCode(0);
        evaluateVo.setMsg("");
        IPage<Evaluate> evaluateIPage = new Page<>(page,limit);
        IPage<Evaluate> result = evaluatemapper.selectPage(evaluateIPage,null);
        evaluateVo.setCount(result.getTotal());
        List<Evaluate> evaluateList = result.getRecords();
        List<AllEvaluateVo> allEvaluateVoList = new ArrayList<>();
        for (Evaluate evaluate1 : evaluateList){
            AllEvaluateVo allEvaluateVo = new AllEvaluateVo();
            BeanUtils.copyProperties(evaluate1,allEvaluateVo);
            allEvaluateVoList.add(allEvaluateVo);
        }
        evaluateVo.setData(allEvaluateVoList);
        return evaluateVo;
    }
}
